#!/bin/sh
#
# Startup script for the DNS proxy server
#
# chkconfig: - 49 50
# description: This script starts your DNS proxy server

. /etc/rc.d/init.d/functions

OPTIONS="-d -R 8.8.8.8"
HOSTSFILE="/etc/dnspd.hosts"

if [ -f $HOSTSFILE ]; then
    OPTIONS=$OPTIONS" -f "$HOSTSFILE
fi

name="dnsproxy"
exec="/usr/sbin/$name"
pidfile="/var/run/dnspd/dnspd.pid"
lockfile="/var/lock/subsys/dnspd"

[ -f $exec ] || exit 0

RETVAL=0

case "$1" in
  start)
        if [ $UID -ne 0 ] ; then
            echo "This script must be run as root."
            exit 4
        fi
        echo -n "Starting dnsproxy: "
        daemon $exec $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch $lockfile
        ;;
  stop)
        echo -n "Shutting down dnsproxy: "
        killproc $name
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
        ;;
  status)
        status $name
        RETVAL=$?
        ;;
  restart|reload|force-reload)
        $0 stop
        $0 start
        RETVAL=$?
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload|status}"
        exit 2
esac

exit $RETVAL
